
//天使果冻

void Func(const vector<int>& v, vector<int>& resSet)
{
    int size = v.size();
    int maxNum = std::max(v[0], v[1]);
    int secondNum = std::min(v[0], v[1]);
    resSet[2] = secondNum;
    int index_resSet = 3;
    for (int i = 2;i < size;++i)
    {
        if (v[i] >= maxNum)
        {
            secondNum = maxNum;
        }
        else {
            if (v[i] > secondNum)
            {
                secondNum = v[i];
            }
        }
        maxNum = std::max(v[i], maxNum);
        resSet[index_resSet++] = secondNum;
    }
}

int main()
{
    int n = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0;i < n;++i)
    {
        cin >> v[i];
    }
    int q = 0;
    cin >> q;
    vector<int> resSet(n + 1);
    Func(v, resSet);
    for (int i = 0;i < q;++i)
    {
        int x = 0;
        cin >> x;
        cout << resSet[x] << endl;
    }
    return 0;
}